﻿//-----------------------------------------------------------------------
// <copyright file="MainWindow.xaml.cs" company="FER">
//     Copyright (c) All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace NMBP_odb
{
    using System.Windows;

    using GalaSoft.MvvmLight.Messaging;

    using NMBP.Models;
    using NMBP.ViewModels;

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        /// <summary>
        /// Initializes a new instance of the MainWindow class
        /// </summary>
        public MainWindow()
        {
            Messenger.Default.Register<Customer>(
                        this,
                        "MainSentCustomer",
                        (msg) =>
                        {
                            CustomerWindow menuWindow = new CustomerWindow();
                            Messenger.Default.Send<Customer>(msg, "InitializeCustomerwindow");
                            menuWindow.Show();
                            this.Close();
                        });

            Messenger.Default.Register<Worker>(
                        this,
                        "MainSentWorker",
                        (msg) =>
                        {
                            WorkerWindow workerWindow = new WorkerWindow();
                            Messenger.Default.Send<Worker>(msg, "InitializeWorkerWindow");
                            workerWindow.Show();
                            this.Close();
                        });

            InitializeComponent();
            Closing += (s, e) =>
                {
                    ViewModelLocator.ClearMain();
                    Messenger.Default.Unregister(this);
                };
        }
    }
}
